use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProblemSetQuestionList {
    // __typename: String,
    questions: Vec<Question>,
    // has_more: bool,
    // total: u32,
}

impl ProblemSetQuestionList {
    pub fn get_questions(&self) -> &Vec<Question> {
        &self.questions
    }
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ProblemSetQuestionListRequest {
    category_slug: String,
    skip: u32,
    limit: u32,
    filters: RequestFilter,
}

impl ProblemSetQuestionListRequest {
    pub fn new(category_slug: String, skip: u32, limit: u32, filters: RequestFilter) -> Self {
        ProblemSetQuestionListRequest {
            category_slug,
            skip,
            limit,
            filters,
        }
    }
}


#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestFilter {
    search_keywords: String,
}

impl RequestFilter {
    pub fn new(search_keywords: String) -> Self {
        RequestFilter {
            search_keywords
        }
    }
}

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Question {
    frontend_question_id: String,
    title_slug: String,
    difficulty: String
}

impl Question {
    pub fn get_frontend_question_id(&self) -> String {
        self.frontend_question_id.clone()
    }

    pub fn get_title_slug(&self) -> String {
        self.title_slug.clone()
    }
    
    pub fn get_difficulty(&self) -> String {
        self.difficulty.clone()
    }
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TopicsListQueryRequest {
    question_slug: String,
    skip: u32,
    first: u32,
    order_by: String,
    user_input: String,
    tag_slugs: String,
}

impl TopicsListQueryRequest {
    pub fn new(question_slug: String, skip: u32, first: u32, order_by: String, user_input: String, tag_slugs: String) -> Self {
        TopicsListQueryRequest {
            question_slug,
            skip,
            first,
            order_by,
            user_input,
            tag_slugs,
        }
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QuestionSolutionArticles {
    // total_num: u32,
    edges: Vec<Edge>,
}

impl QuestionSolutionArticles {
    pub fn get_edges(&self) -> &Vec<Edge> {
        &self.edges
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Edge {
    node: Node,
}

impl Edge {
    pub fn get_node(&self) -> &Node {
        &self.node
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Node {
    by_leetcode: bool,
    slug: String,
    author: Author,
}

impl Node {
    pub fn get_slug(&self) -> String {
        self.slug.clone()
    }

    pub fn is_by_leetcode(&self) -> bool {
        self.by_leetcode
    }
    
    pub fn get_author(&self) -> &Author {
        &self.author
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Author {
    username: String,
}

impl Author {
    pub fn get_username(&self) -> String {
        self.username.clone()
    }
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DiscussTopicRequest {
    slug: String,
}

impl DiscussTopicRequest {
    pub fn new(slug: String) -> Self {
        DiscussTopicRequest {
            slug,
        }
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SolutionArticle {
    content: String,
}

impl SolutionArticle {
    pub fn get_content(&self) -> &String {
        &self.content
    }
}


#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TranslationRequest{
    title_slug: String,
}

impl TranslationRequest {
    pub fn new(title_slug: String) -> Self {
        TranslationRequest {
            title_slug,
        }
    }
}


#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TranslationQuestion {
    // translated_title: String,
    translated_content: String,
}

impl TranslationQuestion {
    pub fn get_translated_content(&self) -> String {
        self.translated_content.clone()
    }
}